package com.store.app.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.TaskListBean;

import java.util.List;

public class TaskAdapter extends BaseAdapter {
    private Context context;
    private LinearLayoutManager linearLayoutManager;
    private List<TaskListBean> list;

    public TaskAdapter(Context context,List<TaskListBean> list) {
        this.context = context;
        this.list=list;
        linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_task, null);
            holder.tv_title = (TextView) convertView.findViewById(R.id.item_task_title);
            holder.tv_txt = (TextView) convertView.findViewById(R.id.item_task_txt);
            holder.tv_money = (TextView) convertView.findViewById(R.id.item_task_money);
            holder.tv_money_type = (TextView) convertView.findViewById(R.id.item_task_money_tpe);
            holder.tv_date = (TextView) convertView.findViewById(R.id.item_task_date);
            holder.relat_title_no = (RelativeLayout) convertView.findViewById(R.id.item_task_title_no);
            holder.relat_title_no_tv = (TextView) convertView.findViewById(R.id.item_task_title_no_tv2);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_title.setText(list.get(position).getTask_name());
        holder.tv_txt.setText(list.get(position).getDesc1());
        if("gold".equals(list.get(position).getPayment_way_key())) {
            holder.tv_money.setText(list.get(position).getAmount());
            holder.tv_money_type.setText("金币");
        }else{
            holder.tv_money.setText(list.get(position).getAmount());
            holder.tv_money_type.setText("元");
        }
        holder.tv_date.setText("截止时间:"+list.get(position).getExpried_date());
        String proid=list.get(position).getProcessing_id();
        if(TextUtils.isEmpty(proid)){
            holder.relat_title_no.setVisibility(View.GONE);
        }else{
            holder.relat_title_no.setVisibility(View.VISIBLE);
            holder.relat_title_no_tv.setText(proid);
        }
        return convertView;
    }


    public  class ViewHolder {
        public TextView tv_title;               //标题
        public TextView tv_txt;         //内容
        public TextView tv_money;            //奖励金额
        public TextView tv_date;   //截止时间
        public TextView tv_money_type;
        public RelativeLayout relat_title_no;
        public TextView relat_title_no_tv;

    }



}
